﻿<cfsilent>
	<cfscript>
		
		event.setArg("pageTitle", "教学运行 - 教学场地调度 - 教室使用记录");
		
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		
		/* 近1个月的使用记录 */
		timeStart = dateFormat( dateAdd("m", -2, now()), "YYYYMMDD" ) & "000000";
		
		/* 读取教室借用信息 S-成功 C-撤销 */
		sql = "SELECT 
					a.cbr_id, a.proc_stat, 
					a.use_time, a.use_rooms, a.use_week, 
					a.time_sign, 
					b.tch_name, 
					c.institute_short, 
					d.ut_id, d.usage
				FROM t_clsroom_borrow a 
					INNER JOIN t_teacher b ON b.tch_id = a.tch_id 
					INNER JOIN t_institute c ON c.institute_id = a.institute_id 
					INNER JOIN t_clsroom_usetype d ON d.ut_id = a.ut_id 
				WHERE 
					( a.proc_stat = 'S' OR a.proc_stat = 'C' ) 
					AND 
					a.time_sign > :timeStart 
				ORDER BY 
					a.cbr_id DESC ";

		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="timeStart", value=timeStart, cfsqltype="cf_sql_interger" );

		rs_doc = queryObj.execute( sql=sql ).getResult();
		
		/* 生成使用分类信息 */
		typeArray = [];
		
		for ( a=1; a LTE rs_doc.recordCount; a++ ) {
			
			typerSet = [ rs_doc["ut_id"][a], rs_doc["usage"][a] ];
			
			if ( not arrayFind( typeArray, typerSet ) ) {
				arrayAppend( typeArray, typerSet );
			}
		}
		
		if ( arrayLen(typeArray) ) {
			currentTab = event.getArg("Tab", "labType" & typerSet[1]);
		}
		else {
			currentTab = event.getArg("Tab", "labNone");
		}

		
		passArgs = structNew();
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('DEFAULT_EVENT')#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">教学场地调度</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 report"></i>教室预约记录
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				
				<div class="UItab">
					<div class="tabLables">
						<cfloop array="#typeArray#" index="typerSet">
							<span <cfif currentTab eq "labType" & typerSet[1]>class="active"</cfif> id="labType<cfoutput>#typerSet[1]#</cfoutput>" tabTarget="TypeList<cfoutput>#typerSet[1]#</cfoutput>"><cfoutput>#typerSet[2]#</cfoutput></span>
						</cfloop>
						<cfif arrayLen(typeArray) eq 0>
							<span <cfif currentTab eq "labNone">class="active"</cfif> id="labNone" tabTarget="None">提示</span>
						</cfif>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>
				</script>
				
				<!--- 没有借用记录, 系统提示 --->
				<cfif arrayLen(typeArray) eq 0>
					
					<div id="None" class="tabContent">
						
						<div class="systemNotice">
							<h3>系统提示</h3>
							<p class="mln">最近一个月没有审批教室预约</p>
						</div>
						
					</div>
					
				</cfif>
				
				<cfloop array="#typeArray#" index="typerSet">
					
					<div id="TypeList<cfoutput>#typerSet[1]#</cfoutput>" class="tabContent">
						
						<div class="noticeBlock">
							<h3><cfoutput>#typerSet[2]#</cfoutput> 教室借用记录</h3>
							<hr/>
						</div>
						
						<cfscript>
							
							sql = "SELECT 
									cbr_id, proc_stat, use_week, use_time, use_rooms, tch_name, institute_short, time_sign
									FROM query
									WHERE ut_id = :typeId ";
							
							queryObj = new Query( dbtype="query" );
							queryObj.setAttributes( query=rs_doc );
							queryObj.addParam( name="typeId", value=typerSet[1], cfsqltype="cf_sql_char" );

							rs_list = queryObj.execute( sql=sql ).getResult();
							
						</cfscript>

						<table id="docList<cfoutput>#typerSet[1]#</cfoutput>" class="UIEditable">
							<thead>
								<tr>
									<td width="30"></td>
									<td>部门</td>
									<td>负责人</td>
									<td>周次</td>
									<td width="450">预约</td>
									<td>状态</td>
									<td>时间</td>
									<td width="20"></td>
								</tr>
							</thead>
							<tbody>
								<cfset row = 0 />
								<cfloop query="rs_list">
									
									<cfset structInsert( passArgs, "DOCID", rs_list.cbr_id, true ) />
									<cfset row++ />
									
									<tr class="editRows">
										<td class="index"><cfoutput>#row#</cfoutput></td>
										<td><cfoutput>#rs_list.institute_short#</cfoutput></td>
										<td><cfoutput>#rs_list.tch_name#</cfoutput></td>
										<td><span class="numeric"><cfoutput>#rs_list.use_week#</cfoutput></span></td>
										<td><cfoutput>#rs_list.use_time#</cfoutput>, <cfoutput>#rs_list.use_rooms#</cfoutput></td>
										<td><span class="progress<cfoutput>#rs_list.proc_stat#</cfoutput>"><cfoutput>#dictAdvice.getProgressStatus( rs_list.proc_stat )#</cfoutput></span></td>
										<td><span class="numeric"><cfoutput>#datetimeAdvice.formatDateTimeString( rs_list.time_sign, "MM/DD" )#</cfoutput></span></td>
										<td><a href="<cfoutput>#buildURL('classRoomUsageRecordDetail', passArgs)#</cfoutput>" class="stat info"></a></td>
									</tr>
								</cfloop>
								<!--- 移出流水号参数 --->
								<cfset structDelete( passArgs, "DOCID", false ) />
							</tbody>
						</table>
						
					</div>
					
				</cfloop>
				
			</div>
		</li>
	</ul>
</div>